package com.ruoyi.web.xxj.contoller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.xxj.domain.Banner;
import com.ruoyi.web.xxj.service.IBannerService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * banner轮播图Controller
 *
 * @author ruoyi
 * @date 2024-01-20
 */
@Api(tags = "轮播图管理")
@RestController
@RequestMapping("/xxj/banner")
public class BannerController extends BaseController {
    @Autowired
    private IBannerService bannerService;

    /**
     * 查询banner轮播图列表
     */
    @ApiOperation("获取轮播图列表")
    @GetMapping("/list")
    public TableDataInfo<Banner> list(Banner banner) {
        startPage();
        List<Banner> list = bannerService.selectBannerList(banner);
        return getDataTable(list);
    }

    /**
     * 导出banner轮播图列表
     */
    @Log(title = "banner轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Banner banner) {
        List<Banner> list = bannerService.selectBannerList(banner);
        ExcelUtil<Banner> util = new ExcelUtil<Banner>(Banner.class);
        util.exportExcel(response, list, "banner轮播图数据");
    }

    /**
     * 获取banner轮播图详细信息
     */
    @ApiOperation("获取轮播图详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bannerService.selectBannerById(id));
    }

    /**
     * 新增banner轮播图
     */
    @ApiOperation("新增轮播图")
    @Log(title = "banner轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Banner banner) {
        return toAjax(bannerService.insertBanner(banner));
    }

    /**
     * 修改banner轮播图
     */
    @ApiOperation("修改轮播图")
    @Log(title = "banner轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Banner banner) {
        return toAjax(bannerService.updateBanner(banner));
    }

    /**
     * 删除banner轮播图
     */
    @ApiOperation("删除轮播图")
    @Log(title = "banner轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bannerService.deleteBannerByIds(ids));
    }

    /******************************************* 以下是小程序接口 ******************************************************/

    /**
     * 查询banner轮播图列表
     */
    @ApiOperation("[小程序]获取轮播图列表")
    @GetMapping("/miniList")
    public AjaxResult<Banner> miniList() {
    	PageUtils.clearPage();
        List<Banner> list = bannerService.selectBannerList(new Banner(String.valueOf(0),null));
        return success(list);
    }
}
